package com.bcqn.dao;

import com.bcqn.model.Employee;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;


public interface EmployeeMapper {
    int deleteByPrimaryKey(Long id);

    int insert(Employee record);

    int insertSelective(Employee record);

    Employee selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Employee record);

    int updateByPrimaryKey(Employee record);

     /**
     * 根据phone 查找用户
     *
     * @param phone
     * @return Employee
     */
    @Select("select * from t_employee where phone=${phone}")
    Employee selectUserByPhone(@Param("phone") String phone);

    /**
     * 根据email查找用户
     *
     * @param email
     * @return Employee
     */
    @Select("select * from t_employee where email=${email}")
    Employee selectUserByEmail(@Param("email") String email);

     /**
     * 根据userName查找用户
     *
     * @param userName
     * @return Employee
     */
    // @Select("select * from t_employee where user_name=${userName}")
    Employee selectUserByUserName(@Param("userName") String userName);
    /**
     * 根据userName查找用户
     *
     * @param id
     * @return Employee
     */
    @Select("select ee.id, ee.avatar, ee.user_name, ee.status, ee.role,ee.email,ee.phone, ro.resources from t_employee as ee left join (select  ee.id, GROUP_CONCAT(tr.resource) as resources from t_employee as ee left join t_role as tr on tr.name = ee.role group by ee.role, ee.id ) as ro on ro.id = ee.id WHERE ee.id=${id}")
    Employee selectUserInfoByEmployeeId(@Param("id") Long id);
}